package view;

import java.awt.EventQueue;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Toolkit;
import java.io.IOException;
import java.util.ArrayList;

import javax.swing.ImageIcon;
import javax.swing.JWindow;

import arq.OperacoesArquivo;

public class Splash extends JWindow
{
	private static final long serialVersionUID = 1L;
	Image img = Toolkit.getDefaultToolkit().getImage("init.gif");
	ImageIcon imgIcon = new ImageIcon(img);
	@SuppressWarnings("unused")
	private static Splash tss;

	@SuppressWarnings("deprecation")
	public Splash()
	{
		try
		{
			setSize(imgIcon.getIconWidth(), imgIcon.getIconHeight());
			setLocationRelativeTo(null);
			show();
			Thread.sleep(2000);
			dispose();
			EventQueue.invokeLater(new Runnable()
			{
				public void run()
				{
					try
					{
						Janela frame = new Janela();
						frame.setVisible(true);
					} catch (Exception e)
					{
						e.printStackTrace();
					}
				}
			});
		} catch (Exception exception)
		{
			exception.printStackTrace();
		}

	}

	public void paint(Graphics g)
	{
		g.drawImage(img, 0, 0, this);
	}

	public static void main(String[] args) throws IOException
	{
		ArrayList<String> a = new ArrayList<String>();

		a = OperacoesArquivo.Leitura("run.dat");

		if (a.get(a.size() - 1).equals("false"))
		{
			EventQueue.invokeLater(new Runnable()
			{
				public void run()
				{
					try
					{
						Janela frame = new Janela();
						frame.setVisible(true);
					} catch (Exception e)
					{
						e.printStackTrace();
					}
				}
			});
		} else
		{
			tss = new Splash();
		}
	}
}